//
//  CorgiTabBarController.swift
//  weibo
//
//  Created by Corgi on 17/3/19.
//  Copyright © 2017年 cocoaHangTou. All rights reserved.
//

import UIKit

class CorgiTabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        //添加子控制器
        addChildViewControllers()
        
        let myTabBar = CorgiTabBar()
        
        myTabBar.clickClosure = { [weak self] (sender) -> () in

            CorgiComposeView.show(target: self!)
        }
        
        setValue(myTabBar, forKey: "tabBar")
    }

    //封装添加过程
    private func addChildViewControllers() {
        
        addChildViewController(vc: CorgiHomeTableViewController(), title: "首页", imageName: "tabbar_home")
        
        addChildViewController(vc: CorgiMessageTableViewController(), title: "消息", imageName: "tabbar_message_center")
        
        addChildViewController(vc: CorgiDiscoverTableViewController(), title: "发现", imageName: "tabbar_discover")
        
        addChildViewController(vc: CorgiProfileTableViewController(), title: "我", imageName: "tabbar_profile")
        
    }
    
    
    //封装添加控制器
    private func addChildViewController(vc: UIViewController,title: String,imageName: String) {
        
        vc.title = title
        
        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.orange], for: .selected)
        
        vc.tabBarItem.image = UIImage(named: imageName)
        
        vc.tabBarItem.selectedImage = UIImage(named: imageName + "_selected")?.withRenderingMode(.alwaysOriginal)
        
        vc.tabBarItem.badgeValue = nil
        
        vc.tabBarItem.badgeColor = UIColor.red
        
        let nav = CorgiNavigationController(rootViewController: vc)
        
        addChildViewController(nav)
        
    }
}
